import { createVolumeControl } from './createVolumeControl.js';

export function checkForVideoElements() {
  const videoElements = document.querySelectorAll('video');
  if (videoElements.length > 0 && !document.getElementById('chrome-volume-control')) {
    createVolumeControl();
  }
}

export function observeDOMChanges() {
  const observer = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
      if (mutation.addedNodes) {
        mutation.addedNodes.forEach(function(node) {
          if (node.nodeName === 'VIDEO') {
            createVolumeControl();
            observer.disconnect();
          }
        });
      }
    });
  });

  observer.observe(document.body, {
    childList: true,
    subtree: true
  });
}